package com.atguigu.gmall.web.all.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.cart.CartFeignClient;
import com.atguigu.gmall.model.cart.CartInfo;
import com.atguigu.gmall.model.product.SkuInfo;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class CartController {


    @Autowired
    CartFeignClient cartFeignClient;


    @GetMapping("/addCart.html")
    public String addCartHtml(@RequestParam("skuId") Long skuId,
                              @RequestParam("skuNum")Integer skuNum,
                              Model model) {

        //远程调用购物车功能，将商品添加到购物车

        CartInfo cartInfo = cartFeignClient.addToCart(skuId, skuNum);

        SkuInfo skuInfo = new SkuInfo();
        skuInfo.setId(cartInfo.getId());
        skuInfo.setSkuName(cartInfo.getSkuName());
        skuInfo.setSkuDefaultImg(cartInfo.getImgUrl());

        model.addAttribute("skuInfo",skuInfo);
        model.addAttribute("skuNum",skuNum);

        return "cart/addCart";
    }

    @GetMapping("/cart.html")
    public String cartListHtml(){

    //    List<CartInfo> cartInfos = cartFeignClient.listCart();
        return "cart/index";
    }

}
